/* eslint-disable @typescript-eslint/no-explicit-any */
/*
 *  Copyright 2021 Collate
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  http://www.apache.org/licenses/LICENSE-2.0
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

 /**
 * Create a topic entity request
 */
export interface CreateTopic {
    /**
     * Topic clean up policy. For Kafka - `cleanup.policy` configuration.
     */
    cleanupPolicies?: CleanupPolicy[];
    /**
     * Fully qualified name of the domain the Topic belongs to.
     */
    dataAssetDir?: string;
    /**
     * List of fully qualified names of data products this entity is part of.
     */
    dataProducts?: string[];
    /**
     * Description of the topic instance. What it has and how to use it.
     */
    description?: string;
    /**
     * Display Name that identifies this topic.
     */
    displayName?: string;
    /**
     * Fully qualified name of the domain the Topic belongs to.
     */
    domain?: string;
    /**
     * Entity extension data with custom attributes added to the entity.
     */
    extension?: any;
    /**
     * Life Cycle of the entity
     */
    lifeCycle?: LifeCycle;
    /**
     * Maximum message size in bytes. For Kafka - `max.message.bytes` configuration.
     */
    maximumMessageSize?: number;
    messageSchema?:      Topic;
    /**
     * Minimum number replicas in sync to control durability. For Kafka - `min.insync.replicas`
     * configuration.
     */
    minimumInSyncReplicas?: number;
    /**
     * Name that identifies this topic instance uniquely.
     */
    name: string;
    /**
     * Owner of this topic
     */
    owner?: EntityReference;
    /**
     * Number of partitions into which the topic is divided.
     */
    partitions: number;
    /**
     * Replication Factor in integer (more than 1).
     */
    replicationFactor?: number;
    /**
     * Maximum size of a partition in bytes before old data is discarded. For Kafka -
     * `retention.bytes` configuration.
     */
    retentionSize?: number;
    /**
     * Retention time in milliseconds. For Kafka - `retention.ms` configuration.
     */
    retentionTime?: number;
    /**
     * Fully qualified name of the messaging service where this topic is hosted in
     */
    service: string;
    /**
     * Source hash of the entity
     */
    sourceHash?: string;
    /**
     * Source URL of topic.
     */
    sourceUrl?: string;
    /**
     * Tags for this topic
     */
    tags?: TagLabel[];
    /**
     * Contains key/value pair of topic configuration.
     */
    topicConfig?: { [key: string]: any };
}

/**
 * Topic clean up policy. For Kafka - `cleanup.policy` configuration.
 */
export enum CleanupPolicy {
    Compact = "compact",
    Delete = "delete",
}

/**
 * Life Cycle of the entity
 *
 * 此模式定义生命周期属性
 */
export interface LifeCycle {
    /**
     * 关于数据资产访问方面的访问详细信息
     */
    accessed?: AccessDetails;
    /**
     * 关于数据资产创建方面的访问详细信息
     */
    created?: AccessDetails;
    /**
     * 关于数据资产更新方面的访问详细信息
     */
    updated?: AccessDetails;
}

/**
 * 关于数据资产访问方面的访问详细信息
 *
 * 实体的访问详细信息
 *
 * 关于数据资产创建方面的访问详细信息
 *
 * 关于数据资产更新方面的访问详细信息
 */
export interface AccessDetails {
    /**
     * 创建、更新或访问数据资产的用户、流水线或查询
     */
    accessedBy?: EntityReference;
    /**
     * 访问数据资产的任何未在 OpenMetadata 中捕获的过程
     */
    accessedByAProcess?: string;
    /**
     * 数据资产创建、更新或读取的时间戳
     */
    timestamp: number;
}

/**
 * 创建、更新或访问数据资产的用户、流水线或查询
 *
 * This schema defines the EntityReference type used for referencing an entity.
 * EntityReference is used for capturing relationships from one entity to another. For
 * example, a table has an attribute called database of type EntityReference that captures
 * the relationship of a table `belongs to a` database.
 *
 * Owner of this topic
 */
export interface EntityReference {
    /**
     * If true the entity referred to has been soft-deleted.
     */
    deleted?: boolean;
    /**
     * Optional description of entity.
     */
    description?: string;
    /**
     * Display Name that identifies this entity.
     */
    displayName?: string;
    /**
     * Fully qualified name of the entity instance. For entities such as tables, databases
     * fullyQualifiedName is returned in this field. For entities that don't have name hierarchy
     * such as `user` and `team` this will be same as the `name` field.
     */
    fullyQualifiedName?: string;
    /**
     * Link to the entity resource.
     */
    href?: string;
    /**
     * Unique identifier that identifies an entity instance.
     */
    id: string;
    /**
     * If true the relationship indicated by this entity reference is inherited from the parent
     * entity.
     */
    inherited?: boolean;
    /**
     * Name of the entity instance.
     */
    name?: string;
    /**
     * Entity type/class name - Examples: `database`, `table`, `metrics`, `databaseService`,
     * `dashboardService`...
     */
    type: string;
}

/**
 * 此模式定义了Topic实体，Topic是由发布者发布消息到其中，并由消息服务中的消费者读取的源
 */
export interface Topic {
    /**
     * 此表中的列
     */
    schemaFields?: Field[];
    /**
     * 用于消息序列化的模式，某些主题可能没有关联的模式，因此此项为可选
     */
    schemaText?: string;
    /**
     * 用于消息序列化的模式
     */
    schemaType?: SchemaType;
    [property: string]: any;
}

/**
 * 此模式定义了用于捕获Topic模式的protobuf/avro/jsonschema的嵌套对象
 */
export interface Field {
    /**
     * 如果dataType或arrayDataType是`map`，`record`，`message`，则为子字段
     */
    children?: Field[];
    /**
     * 字段的数据类型（int、date等）
     */
    dataType: DataTypeTopic;
    /**
     * dataType的显示名称，对于复杂类型（如`array<int>`，`map<int,string>`，`struct<>`和union类型），这非常有用
     */
    dataTypeDisplay?: string;
    /**
     * 列的描述
     */
    description?: string;
    /**
     * 标识此字段名称的显示名称
     */
    displayName?:        string;
    fullyQualifiedName?: string;
    name:                string;
    /**
     * 与列关联的标签
     */
    tags?: TagLabel[];
}

/**
 * 字段的数据类型（int、date等）
 *
 * 此枚举定义模式中定义的数据类型
 */
export enum DataTypeTopic {
    Array = "ARRAY",
    Boolean = "BOOLEAN",
    Bytes = "BYTES",
    Date = "DATE",
    Double = "DOUBLE",
    Enum = "ENUM",
    Error = "ERROR",
    Fixed = "FIXED",
    Float = "FLOAT",
    Int = "INT",
    Long = "LONG",
    Map = "MAP",
    Null = "NULL",
    Record = "RECORD",
    String = "STRING",
    Time = "TIME",
    Timestamp = "TIMESTAMP",
    Timestampz = "TIMESTAMPZ",
    Union = "UNION",
    Unknown = "UNKNOWN",
}

/**
 * 此模式定义了用于使用标签标记实体的标签类型
 */
export interface TagLabel {
    /**
     * 标签标签的描述
     */
    description?: string;
    /**
     * 标识此标签的显示名称
     */
    displayName?: string;
    /**
     * 到标签资源的链接
     */
    href?: string;
    /**
     *
     * 标签类型描述标签标签是如何应用的，'Manual'表示标签标签是由人员应用的。'Derived'表示使用关联的标签关系导出了标签标签（有关详细信息，请参见Classification.json）。'Propagated`表示标签标签是根据血统从上游传播的。'Automated'在使用工具确定标签标签时使用。
     */
    labelType: LabelType;
    /**
     * 标签或词汇术语的名称
     */
    name?: string;
    /**
     * 标签来自标签还是词汇表
     */
    source: TagSource;
    /**
     * 'Suggested'状态在用户或工具建议标签标签时使用。实体的所有者必须在将其标记为'Confirmed'之前确认建议的标签
     */
    state:  State;
    style?: Style;
    tagFQN: string;
}

/**
 *
 * 标签类型描述标签标签是如何应用的，'Manual'表示标签标签是由人员应用的。'Derived'表示使用关联的标签关系导出了标签标签（有关详细信息，请参见Classification.json）。'Propagated`表示标签标签是根据血统从上游传播的。'Automated'在使用工具确定标签标签时使用。
 */
export enum LabelType {
    Automated = "Automated",
    Derived = "Derived",
    Manual = "Manual",
    Propagated = "Propagated",
}

/**
 * 标签来自标签还是词汇表
 */
export enum TagSource {
    Classification = "Classification",
    Glossary = "Glossary",
}

/**
 * 'Suggested'状态在用户或工具建议标签标签时使用。实体的所有者必须在将其标记为'Confirmed'之前确认建议的标签
 */
export enum State {
    Confirmed = "Confirmed",
    Suggested = "Suggested",
}

/**
 * UI Style is used to associate a color code and/or icon to entity to customize the look of
 * that entity in UI.
 */
export interface Style {
    /**
     * Hex Color Code to mark an entity such as GlossaryTerm, Tag, Domain or Data Product.
     */
    color?: string;
    /**
     * An icon to associate with GlossaryTerm, Tag, Domain or Data Product.
     */
    iconURL?: string;
}

/**
 * 用于消息序列化的模式
 *
 * 用于消息的模式类型
 */
export enum SchemaType {
    Avro = "Avro",
    JSON = "JSON",
    None = "None",
    Other = "Other",
    Protobuf = "Protobuf",
}
